package com.smm.service;

import com.jn.sqlhelper.dialect.pagination.PagingRequest;
import com.jn.sqlhelper.dialect.pagination.PagingRequestContextHolder;
import com.jn.sqlhelper.dialect.pagination.PagingResult;
import com.smm.dao.SongDao;
import com.smm.entity.Song;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SongService {
    @Resource
    SongDao songDao;

    public PagingResult findSongPage(Song song, Integer pageSize, Integer pageNumber) {
        PagingRequest request = new PagingRequest().setPageNo(pageNumber).setPageSize(pageSize);
        PagingRequestContextHolder.getContext().setPagingRequest(request);
        List<Song> songs = songDao.findSongPage(song);
        return request.getResult().setItems(songs);
    }

    public Integer addSong(Song song) {
        return songDao.addSong(song);
    }

    public Integer deleteSong(Integer id) {
        return songDao.deleteSong(id);
    }

    public Song findSong(Song song) {
        return songDao.findSong(song);
    }

    public Integer updateSong(Song song) {
        return songDao.updateSong(song);
    }

    public Song getCollect(Integer id) {
        return songDao.getCollectBySongId(id);
    }
}
